#include "RtpPacket.hpp"

static void DefaultUserRelease(uint8_t* buffer){};
namespace Hi {
	RtpPacket::RtpPacket(RtpPacket::Header *header, 
						RtpPacket::ExtensionHeader *extensionHeader,
						const uint8_t *payload, 
						size_t payloadLength, 
						uint8_t payloadPadding, 
						size_t size)
		: header(header),
		extensionHeader(extensionHeader),
		payload(const_cast<uint8_t *>(payload)), 
		payloadLength(payloadLength),
		payloadPadding(payloadPadding), 
		size(size),
		releaseFunc(DefaultUserRelease)
	{
		if (this->header->csrcCount != 0u) {
			this->csrcList = reinterpret_cast<uint8_t *>(header) + sizeof(Header);
		}

		// Parse RFC 5285 extension header.
		this->ParseExtensions();
	}

	RtpPacket::~RtpPacket()	{
		if (!this->satelliteMemory)  {
			return;
		}
		if (!usingUserReleaseFun) {
			delete[] this->satelliteMemory;
			this->satelliteMemory = nullptr;
			return;
		}
		releaseFunc(this->satelliteMemory);
		this->satelliteMemory = nullptr;
	}
} // namespace Hi End
